from django.http import HttpResponse
from django.shortcuts import render, redirect, reverse
from django.views.generic import View
# from .forms import AddBookForm

def index(request):
    return render(request,'front9/index.html')

# def add_book(request):
#     form = AddBookForm(request.POST)
#     if form.is_valid():
#         title = form.cleaned_data.get('title')
#         page = form.cleaned_data.get('page')
#         price = form.cleaned_data.get('price')
#         print(
#             {'title':title,'page':page,'price':price}
#         )
#         return HttpResponse("seccess")
#     else:
#         print(form.errors.get_json_data())
#         return HttpResponse("FALE")


class IndexView(View):
    def get(self,request):
        return render(request,'front9/index.html')

    def post(self,request):
        myfile = request.FILES.get('myfile')
        with open('somefile.txt','wb') as fp:
            for chunk in myfile.chunks():
                fp.write(chunk)
        return HttpResponse('success')